package com.gz.tank;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

public class tankganme extends JFrame {
    Mypanel mypanel=null;

    public static void main(String[] args) {
        new tankganme();
    }

    public tankganme() {
        Scanner scanner = new Scanner(System.in);
        String key=null;
        while(true){
            System.out.println("请选择:");
            System.out.println("0. 重新开始");
            System.out.println("1. 继续游戏");
            key=scanner.next();
            if(key.equals("0")||key.equals("1")){
                break;
            }
            System.out.println("输入有误，请重新输入\n");
        }

        mypanel=new Mypanel(key);
        Thread thread=new Thread(mypanel);
        thread.start();//重绘子弹
        this.add(mypanel);
        this.setSize(1300,950);
        this.addKeyListener(mypanel);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //在Jframe中增加关闭窗口时相应处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecorder();
                System.out.println("监听到关闭窗口了~");
                System.exit(0);
            }
        });
    }
}
